package com.example.service;

import com.example.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class JwtBlacklistService {

    @Autowired
    private StringRedisTemplate redisTemplate;

    public void addToBlacklist(String token, Long expiration) {
        // 使用MD5生成键
        String key = MD5Utils.md5(token);
        redisTemplate.opsForValue().set(key, "blacklisted", expiration, TimeUnit.SECONDS);
    }

    public boolean isTokenBlacklisted(String token) {
        String key = MD5Utils.md5(token);
        return Boolean.TRUE.equals(redisTemplate.hasKey(key));
    }
}
